﻿using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Collections.Generic;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using BussinessLogicTecnoPez;
using BussinessLogicTecnoPez.Produccion.Enfermedades_y_control_de_estanques;

public partial class Modules_EnfermedadesControlEstanque_ConsultaAlarmas : System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e)
    {
        InicializarGrilla(); 

        GenericMasterPage master = (GenericMasterPage)this.Master;
        master.Imagen = "../Styles/Icons/alert.png";
        master.Titulo = "Consulta de alertas";
        cargarGrilla();

        this.tppSensor.ObjType = typeof(Sensor);
    }

    private void InicializarGrilla()
    {
        tdgAlertas.setupGrid(typeof(Alerta), cargarGrilla, true, true, this.ViewState,(new DataControlField[0]));
    }

    private void cargarGrilla()
    {
        Alerta.getManager.ClearFilters();
        Alerta.getManager.ClearOrders();

        Sensor sensorElejido = (Sensor)tppSensor.ItemSelected;

        if (sensorElejido != null)
        {
            Alerta.getManager.AddFilter("Sensor", GenericManager<Alerta>.filterOperator.Equals, sensorElejido.Codigo);
        }
        if (tpcFechaDesde.Text != "")
        {
            DateTime fecha;
            if (DateTime.TryParse(tpcFechaDesde.Text, out fecha))
            {
                Alerta.getManager.AddFilter("Fecha", GenericManager<Alerta>.filterOperator.BiggerEqualsThan, fecha);
            }
        }
        if(tpcFechaHasta.Text!="")
        {
            DateTime fecha;
            if (DateTime.TryParse(tpcFechaHasta.Text, out fecha))
            {
                Alerta.getManager.AddFilter("Fecha", GenericManager<Alerta>.filterOperator.SmallerEqualsThan, fecha);
            }
        }

        if (ViewState[tdgAlertas.PageDataViewOrderKey] == null)
        {
            Alerta.getManager.AddOrder("IdAlerta", GenericManager<Alerta>.Order.orderDirection.DESC);
        }
        else
        {
            Alerta.getManager.AddOrder(ViewState[tdgAlertas.PageDataViewOrderKey].ToString(), (GenericManager<Alerta>.Order.orderDirection)ViewState[tdgAlertas.PageDataViewOrdenDireccionKey]);
        }

        List<Alerta> lista = new List<Alerta>();
        lista = Alerta.getManager.GetFilter();
        tdgAlertas.DataSource = lista;
        tdgAlertas.DataBind();

    }

    protected void cmdBuscar_Click(object sender, EventArgs e)
    {

    }
}
